<?php defined('_JEXEC') or die('Restricted access'); ?>
<script language="javascript" type="text/javascript">
	function dosubmit(form, task) {
		if (form) {
			form.task.value = task;
			form.submit();
		}
	}

	function checkInputValues() {
		var elem = null;
		var names = new Array('mtrsmen', 'parmen', 'indexmen1', 'indexmen2', 'mtrswomen', 'parwomen', 'indexwomen1', 'indexwomen2', 'indexwomen3');
		for (i = 0; i < names.length; i++) {
			for (j = 1; j <= 18; j++) {
				elem = document.getElementById('holes[' + j + ']' + '[' + names[i] + ']');
				if (elem.value && isNaN(elem.value)) {
					alert('Input value is not valid. Reinput please!');
					elem.focus();
					elem.select();
					return false;
				}
			}
		}
		elem = document.getElementById('acr');
		if (elem.value && isNaN(elem.value)) {
			alert('A.C.R value is not valid. Reinput please!');
			elem.focus();
			elem.select();
			return false;
		}
		elem = document.getElementById('awcr');
		if (elem.value && isNaN(elem.value)) {
			alert('A.W.C.R value is not valid. Reinput please!');
			elem.focus();
			elem.select();
			return false;
		}
		return true;
	}

	function submitform() {
		var form = document.courseform;

		if (form.name.value == "") {
			alert( "<?php echo JText::_( 'Please enter the club name.', true );?>" );
		} else if (checkInputValues()){
			dosubmit(form, 'addCourse');
		}
	}
</script>

<table class="contentpaneopen">
	<tbody>
		<tr>
			<td class="contentheading"><?php echo JText::_('My Golf Scorecard'); ?></td>
		</tr>
	</tbody>
</table>

<form action="" method="POST" name="courseform">
	<div class="scorecard_box">
		<h3><?php echo JText::_('Golf Club Information'); ?></h3>
		<table>
			<tbody>
				<tr>
					<td><?php echo JText::_('Club Name:'); ?></td>
					<td>
						<input type="text" class="inputbox" name="name" id="name" tabindex="1" value="<?php echo $this->post['name']; ?>"/>
					</td>
					<td><?php echo JText::_('Phone:'); ?></td>
					<td>
						<input type="text" name="phone" id="phone"  tabindex="7" value="<?php echo $this->post['phone']; ?>"/>
					</td>
				</tr>
				<tr>
					<td><?php echo JText::_('Address:'); ?></td>
					<td>
						<input type="text" name="address" id="address" tabindex="2" value="<?php echo $this->post['address']; ?>"/>
					</td>

					<td><?php echo JText::_('Fax:'); ?></td>
					<td>
						<input type="text" name="fax" id="fax" tabindex="8" value="<?php echo $this->post['fax']; ?>"/>
					</td>
				</tr>
				<tr>
					<td></td>
					<td>
						<input type="text" name="otheraddress" id="otheraddress" tabindex="3" value="<?php echo $this->post['otheraddress']; ?>"/>
					</td>
					<td><?php echo JText::_('Email:'); ?></td>
					<td>
						<input type="text" name="email" id="email" tabindex="9" value="<?php echo $this->post['email']; ?>"/>
					</td>
				</tr>
				<tr>
					<td><?php echo JText::_('Suburb:'); ?></td>
					<td>
						<input type="text" name="suburb" id="suburb" tabindex="4" value="<?php echo $this->post['suburb']; ?>"/>
					</td>

					<td><?php echo JText::_('Website:'); ?></td>
					<td>
						<input type="text" name="website" id="website" tabindex="10" value="<?php echo $this->post['website']; ?>"/>
					</td>
				</tr>
				<tr>
					<td><?php echo JText::_('State:'); ?></td>
					<td>
						<?php if($this->state):?>
							<?php echo $this->state; ?>
						<?php endif; ?>
					</td>

					<td><?php echo JText::_('Status:'); ?></td>
					<td>
						<?php if($this->status): ?>
							<?php echo $this->status; ?>
						<?php endif; ?>
					</td>
				</tr>
				<tr>
					<td><?php echo JText::_('Country:'); ?></td>
					<td>
						<?php if($this->country):?>
							<?php echo $this->country; ?>
						<?php endif; ?>
					</td>
					<td></td>
					<td></td>
				</tr>
			</tbody>
		</table>
	</div>


	<div class="scorecard_box"  style="height: 500px">
		<h3><?php echo JText::_('Scorecard'); ?></h3>
		<div class="left">
		<table class="card" cellspacing="0">
			<tbody>
				<tr>
					<td></td>
					<td colspan="4">MEN</td>
					<td colspan="5">WOMEN</td>
					<td colspan="2">PLAYER</td>
				</tr>
				<tr>
					<td>H<br>O<br>L<br>E</td>
					<td>M<br>T<br>R<br>S</td>
					<td>P<br>A<br>R</td>
					<td colspan="2">INDEX</td>
					<td>M<br>T<br>R<br>S</td>
					<td>P<br>A<br>R</td>
					<td colspan="3">INDEX</td>
					<td>M</td>
					<td>W</td>
				</tr>
				<?php for($i = 1; $i <= 9; $i++): ?>
					<tr>
						<td><?php echo $i; ?></td>
						<?php if($this->post['scorecardid']): ?>
							<input type="hidden" name="holes[<?php echo $i; ?>][id]" id="holes[<?php echo $i; ?>][id]" value="<?php echo $this->post["holes"][$i]["id"]; ?>"/>
						<?php endif; ?>

						<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+11; ?>" name="holes[<?php echo $i; ?>][mtrsmen]" id="holes[<?php echo $i; ?>][mtrsmen]" value="<?php echo ($this->post["holes"][$i]["mtrsmen"] != 0 ? $this->post["holes"][$i]["mtrsmen"] : ''); ?>"/></td>
						<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+1*9+11; ?>" name="holes[<?php echo $i; ?>][parmen]" id="holes[<?php echo $i; ?>][parmen]" value="<?php echo ($this->post["holes"][$i]["parmen"] != 0 ? $this->post["holes"][$i]["parmen"] : ''); ?>"/></td>
						<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+2*9+11; ?>" name="holes[<?php echo $i; ?>][indexmen1]" id="holes[<?php echo $i; ?>][indexmen1]" value="<?php echo ($this->post["holes"][$i]["indexmen1"] !=0 ? $this->post["holes"][$i]["indexmen1"] : '') ; ?>"/></td>
						<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+3*9+11; ?>" name="holes[<?php echo $i; ?>][indexmen2]" id="holes[<?php echo $i; ?>][indexmen2]" value="<?php echo ($this->post["holes"][$i]["indexmen2"] !=0 ? $this->post["holes"][$i]["indexmen2"] : ''); ?>"/></td>
						<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+4*9+11; ?>" name="holes[<?php echo $i; ?>][mtrswomen]" id="holes[<?php echo $i; ?>][mtrswomen]" value="<?php echo ($this->post["holes"][$i]["mtrswomen"] != 0 ? $this->post["holes"][$i]["mtrswomen"] : ''); ?>"/></td>
						<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+5*9+11; ?>" name="holes[<?php echo $i; ?>][parwomen]" id="holes[<?php echo $i; ?>][parwomen]" value="<?php echo ($this->post["holes"][$i]["parwomen"] != 0 ? $this->post["holes"][$i]["parwomen"] : ''); ?>"/></td>
						<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+6*9+11; ?>" name="holes[<?php echo $i; ?>][indexwomen1]" id="holes[<?php echo $i; ?>][indexwomen1]" value="<?php echo ($this->post["holes"][$i]["indexwomen1"] != 0 ? $this->post["holes"][$i]["indexwomen1"] : ''); ?>"/></td>
						<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+7*9+11; ?>" name="holes[<?php echo $i; ?>][indexwomen2]" id="holes[<?php echo $i; ?>][indexwomen2]"value="<?php echo ($this->post["holes"][$i]["indexwomen2"] != 0 ? $this->post["holes"][$i]["indexwomen2"] : ''); ?>"/></td>
						<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+8*9+11; ?>" name="holes[<?php echo $i; ?>][indexwomen3]" id="holes[<?php echo $i; ?>][indexwomen3]" value="<?php echo ($this->post["holes"][$i]["indexwomen3"] != 0 ? $this->post["holes"][$i]["indexwomen3"] : ''); ?>"/></td>

						<td class="inputcell_readonly"></td>
						<td class="inputcell_readonly"></td>
					</tr>
				<?php endfor; ?>
			</tbody>
		</table>
		</div>

		<div class="right">
			<table class="card" cellspacing="0">
				<tbody>
					<tr>
						<td></td>
						<td colspan="4">MEN</td>
						<td colspan="5">WOMEN</td>
						<td colspan="2">PLAYER</td>
					</tr>
					<tr>
						<td>H<br>O<br>L<br>E</td>
						<td>M<br>T<br>R<br>S</td>
						<td>P<br>A<br>R</td>
						<td colspan="2">INDEX</td>
						<td>M<br>T<br>R<br>S</td>
						<td>P<br>A<br>R</td>
						<td colspan="3">INDEX</td>
						<td>M</td>
						<td>W</td>
					</tr>
					<?php for($i = 10; $i <= 18; $i++): ?>
						<tr>
							<td><?php echo $i; ?></td>
							<?php if($this->post['scorecardid']): ?>
								<input type="hidden" name="holes[<?php echo $i; ?>][id]" id="holes[<?php echo $i; ?>][id]" value="<?php echo $this->post["holes"][$i]["id"]; ?>"/>
							<?php endif; ?>

							<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+9*9+11; ?>" name="holes[<?php echo $i; ?>][mtrsmen]" id="holes[<?php echo $i; ?>][mtrsmen]" value="<?php echo ($this->post["holes"][$i]["mtrsmen"] != 0 ? $this->post["holes"][$i]["mtrsmen"] : ''); ?>"/></td>
							<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+10*9+11; ?>" name="holes[<?php echo $i; ?>][parmen]" id="holes[<?php echo $i; ?>][parmen]" value="<?php echo ($this->post["holes"][$i]["parmen"] != 0 ? $this->post["holes"][$i]["parmen"] : ''); ?>"/></td>
							<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+11*9+11; ?>" name="holes[<?php echo $i; ?>][indexmen1]" id="holes[<?php echo $i; ?>][indexmen1]" value="<?php echo ($this->post["holes"][$i]["indexmen1"] !=0 ? $this->post["holes"][$i]["indexmen1"] : '') ; ?>"/></td>
							<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+12*9+11; ?>" name="holes[<?php echo $i; ?>][indexmen2]" id="holes[<?php echo $i; ?>][indexmen2]" value="<?php echo ($this->post["holes"][$i]["indexmen2"] !=0 ? $this->post["holes"][$i]["indexmen2"] : ''); ?>"/></td>
							<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+13*9+11; ?>" name="holes[<?php echo $i; ?>][mtrswomen]" id="holes[<?php echo $i; ?>][mtrswomen]" value="<?php echo ($this->post["holes"][$i]["mtrswomen"] != 0 ? $this->post["holes"][$i]["mtrswomen"] : ''); ?>"/></td>
							<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+14*9+11; ?>" name="holes[<?php echo $i; ?>][parwomen]" id="holes[<?php echo $i; ?>][parwomen]" value="<?php echo ($this->post["holes"][$i]["parwomen"] != 0 ? $this->post["holes"][$i]["parwomen"] : ''); ?>"/></td>
							<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+15*9+11; ?>" name="holes[<?php echo $i; ?>][indexwomen1]" id="holes[<?php echo $i; ?>][indexwomen1]" value="<?php echo ($this->post["holes"][$i]["indexwomen1"] != 0 ? $this->post["holes"][$i]["indexwomen1"] : ''); ?>"/></td>
							<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+16*9+11; ?>" name="holes[<?php echo $i; ?>][indexwomen2]" id="holes[<?php echo $i; ?>][indexwomen2]"value="<?php echo ($this->post["holes"][$i]["indexwomen2"] != 0 ? $this->post["holes"][$i]["indexwomen2"] : ''); ?>"/></td>
							<td class="inputcell"><input type="text" class="celledit" maxlength="5" tabindex="<?php echo $i+17*9+11; ?>" name="holes[<?php echo $i; ?>][indexwomen3]" id="holes[<?php echo $i; ?>][indexwomen3]" value="<?php echo ($this->post["holes"][$i]["indexwomen3"] != 0 ? $this->post["holes"][$i]["indexwomen3"] : ''); ?>"/></td>

							<td class="inputcell_readonly"></td>
							<td class="inputcell_readonly"></td>
						</tr>
					<?php endfor; ?>
				</tbody>
			</table>

			<div style="height:120px; margin-top: 10px">
				<div style="width:100px;float:left;margin-right:10px;">
					<table class="card" cellspacing="0" cellpadding="0">
						<tr>
							<td>IN</td>
							<td class="inputcell_readonly">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
						</tr>
						<tr>
							<td>OUT</td>
							<td class="inputcell_readonly">&nbsp;</td>
						</tr>
						<tr>
							<td>TOTAL</td>
							<td class="inputcell_readonly">&nbsp;</td>
						</tr>
					</table>
				</div>

				<div style="width:100px;">
					<table class="card" cellspacing="0">
						<tr>
							<td>A.C.R</td>
							<td class="inputcell"><input type="text" name="acr" id="acr" tabindex="183" class="celledit" maxlength="5" value="<?php echo $this->post['acr']; ?>"/></td>
						</tr>
						<tr>
							<td>A.W.C.R</td>
							<td class="inputcell"><input type="text" name="awcr" id="awcr" tabindex="184" class="celledit" maxlength="5" value="<?php echo $this->post['awcr']?>"/></td>
						</tr>
					</table>
				</div>
			</div>
		</div>
	</div>

	<div style="text-align: right">
		<input type="button" class="button" value="Cancel" onclick="document.location.href='index.php?option=com_scorecard&view=score&Itemid=<?php echo $this->itemid; ?>'"/>
		<input type="button" class="button" value="Save" tabindex="185" onclick="submitform();"/>
	</div>
	<input type="hidden" name="option" value="<?php echo $option; ?>"/>
	<input type="hidden" name="task" value=""/>
	<input type="hidden" name="Itemid" value="<?php echo $this->itemid; ?>"/>
	<?php if($this->post['courseid']):?>
		<input type="hidden" name="courseid" id="courseid" value="<?php echo $this->post['courseid']; ?>"/>
	<?php endif; ?>
	<?php if($this->post['scorecardid']):?>
		<input type="hidden" name="scorecardid" id="scorecardid" value="<?php echo $this->post['scorecardid']; ?>"/>
	<?php endif; ?>
</form>




